﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using BiliBiliiMG.Model;
using BilibiliDAL;

namespace BilibiliIMGBLL
{
    public class LeaveCommentsBll
    {
        private readonly LeaveCommentsDal dal = new LeaveCommentsDal();
        public LeaveCommentsBll()
        { }

        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int UnitID)
        {
            return dal.Exists(UnitID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(LeaveCommentsModel model)
        {
            return dal.Add(model);

        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(LeaveCommentsModel model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int UnitID)
        {

            return dal.Delete(UnitID);
        }
        /// <summary>
        /// 批量删除一批数据
        /// </summary>
        public bool DeleteList(string UnitIDlist)
        {
            return dal.DeleteList(UnitIDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public LeaveCommentsModel GetModel(int UnitID)
        {

            return dal.GetModel(UnitID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        //public LeaveCommentsModel GetModelByCache(int UnitID)
        //{

        //    string CacheKey = "LeaveCommentsModel-" + UnitID;
        //    object objModel = Common.DataCache.GetCache(CacheKey);
        //    if (objModel == null)
        //    {
        //        try
        //        {
        //            objModel = dal.GetModel(UnitID);
        //            if (objModel != null)
        //            {
        //                int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
        //                Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
        //            }
        //        }
        //        catch { }
        //    }
        //    return (Maticsoft.Model.LeaveComments)objModel;
        //}

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<LeaveCommentsModel> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<LeaveCommentsModel> DataTableToList(DataTable dt)
        {
            List<LeaveCommentsModel> modelList = new List<LeaveCommentsModel>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                LeaveCommentsModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new LeaveCommentsModel();
                    if (dt.Rows[n]["UnitID"].ToString() != "")
                    {
                        model.UnitID = int.Parse(dt.Rows[n]["UnitID"].ToString());
                    }
                    if (dt.Rows[n]["PUnitID"].ToString() != "")
                    {
                        model.PUnitID = int.Parse(dt.Rows[n]["PUnitID"].ToString());
                    }
                    model.IPAddress = dt.Rows[n]["IPAddress"].ToString();
                    model.Content = dt.Rows[n]["Content"].ToString();
                    if (dt.Rows[n]["IsDelect"].ToString() != "")
                    {
                        model.IsDelect = int.Parse(dt.Rows[n]["IsDelect"].ToString());
                    }
                    if (dt.Rows[n]["IsDisplay"].ToString() != "")
                    {
                        model.IsDisplay = int.Parse(dt.Rows[n]["IsDisplay"].ToString());
                    }
                    if (dt.Rows[n]["CreateTime"].ToString() != "")
                    {
                        model.CreateTime = DateTime.Parse(dt.Rows[n]["CreateTime"].ToString());
                    }
                    model.Name = dt.Rows[n]["Name"].ToString();
                    if (dt.Rows[n]["ReviseTime"].ToString() != "")
                    {
                        model.ReviseTime = DateTime.Parse(dt.Rows[n]["ReviseTime"].ToString());
                    }


                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }
        #endregion
    }
}